package com.think.test;

import junit.framework.TestCase;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;

import java.util.EnumSet;

public class CreateDB extends TestCase {
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
    Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
    SchemaExport schemaExport = new SchemaExport();

    //hibernate 5.x
    public void testCreateDB() {
        schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata);
    }

    //hibernate 5.x
    public void testDropDB() {
        schemaExport.drop(EnumSet.of(TargetType.DATABASE), metadata);
    }

    //hibernate 4.x
    /*public void testDropDB() {
        Configuration cf= HibernateConfigurationUtil.getConfigure();
        cf.configure();
        SchemaExport se = new SchemaExport(cf);
        se.drop(true, true);
    }*/

    //hibernate 4.x
	/*public void testCreateDB2() {
		Configuration cf= HibernateConfigurationUtil.getConfigure();
		cf.configure();
		SchemaExport se = new SchemaExport(cf);
		//se.setOutputFile("create_table.sql");
		se.create();
	}*/
}
